class Solution {
    bool __isSymmetric(TreeNode* left, TreeNode* right)
    {
        if (!left && !right) return true;
        if (!left || !right) return false;
        if (left->val != right->val) return false;
        return __isSymmetric(left->left, right->right) && __isSymmetric(left->right, right->left);
    }
public:
    bool isSymmetric(TreeNode* root) {
        if (!root) return true;
        return __isSymmetric(root->left, root->right);
    }
};